package cn.alm.springaialibaba.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("client")
public class ChatClientController {

    @Autowired
    private ChatClient chatClient;

    @GetMapping("chat")
    public String chat(@RequestParam String question) {
        String content = chatClient.prompt().user(question).call().content();
        return content;
    }

    @GetMapping(value = "stream", produces = "text/html;charset=UTF-8")
    public Flux<String> stream(@RequestParam String question) {
        Flux<String> content = chatClient.prompt().user(question).stream().content();
        return content;
    }
}
